/**
 * 数组解构
 */
// 1.变量个数和数组个数相同的解构(变量和数组元素一一对应)
var arr = ['tom', 'jeery', 'jacky', 'doinb', 'clearlove8'];
let [a, b, c, d, e] = arr;
console.log(a, b, c, d, e); // tom jeery jacky doinb clearlove8

// 2.变量个数比数组元素个数少的解构
var arr = ['tom', 'jeery', 'jacky', 'doinb', 'clearlove8'];
let [a, b] = arr;
console.log(a, b); // tom jeery
// 3. 变量个数比数组元素个数多的解构
var arr = ['tom', 'jeery', 'jacky', 'doinb', 'clearlove8'];
let [a, b, c, d, e, f, g, h, i] = arr;
console.log(a, b, c, d, e, f, g, h, i); // tom jeery jacky doinb clearlove8 undefined undefined undefined undefined
// 4.使用丢弃变量进行解构
var arr = ['tom', 'jeery', 'jacky', 'doinb', 'clearlove8'];
let [a, , , d] = arr;
console.log(a, d); // tom doinb

// 5.使用可变变量进行解构
var arr = ['tom', 'jeery', 'jacky', 'doinb', 'clearlove8'];
let [a, b, ...c] = arr;
console.log(a, b); // tom jeery
console.log(c); // [ 'jacky', 'doinb', 'clearlove8' ]

// 6.使用缺省值进行解构
var arr = ['tom', 'jeery', 'jacky', 'doinb', 'clearlove8'];
let [a, b, c=100, d, e=200, f=300] = arr;
console.log(a, b, c, d, e, f); // tom jeery jacky doinb clearlove8 300

// 7.解构展开数组
const [a, b, ...rest] = [10, 20, 30, 40, 50];
console.log(a); // 10
console.log(b); // 20
console.log(rest); // [30, 40, 50]

/**
 * 对象解构
 * */
// 1.基本赋值
var o = {p: 42, q: true};
var {p, q} = o;

console.log(p); // 42
console.log(q); // true

// 2.无声明赋值
var a, b;

({a, b} = {a: 1, b: 2});
console.log(a) // 1
console.log(b) // 2

// 3.给新的变量名赋值
var o = {p: 42, q: true};
var {p: foo, q: bar} = o;
 
console.log(foo); // 42 
console.log(bar); // true

// 4.给变量赋默认值
var {a:aa = 10, b:bb = 5} = {a: 3};
 
console.log(aa); // 3
console.log(bb); // 5

// 5.给新的变量名赋值并赋默认值

var {a:aa = 10, b:bb = 5} = {a: 3};
 
console.log(aa); // 3
console.log(bb); // 5
// 6.解构嵌套对象和数组
//7.对象属性计算名和解构
